import pymysql
from pyecharts import options
from pyecharts.charts import Bar

db=pymysql.connect(
    host="localhost",
    port=3306,
    user="root",
    password="4416",
    charset="utf8",
    database="crawlerdemo"
)
cursor=db.cursor()
sql="select avg(job_sal),job_place from job group by job_place order by avg(job_sal) desc limit 5"
sal=[]
city=[]

try:
    cursor.execute(sql)
    res=cursor.fetchall()
    for i in res:
        sal.append(i[0])
        city.append(i[1])
except:
    print("查询出了问题")
#创建柱状图对象
bar=Bar()
#添加x轴的数据
bar.add_xaxis(city)
#添加轴的数“月薪水/元” 是y轴数的单位
bar.add_yaxis("月薪水/元",sal)
#添加图标的标题
bar.set_global_opts(title_opts=options.TitleOpts(title="平均工资最高的五个城市",subtitle="单位/元"))
bar.render("barmin.html")